PHP calculator instance based on factory mode, php factory calculator instance
The example in this article describes the calculator implemented by PHP Based on the factory mode. Share it with you for your reference. The details are as follows:
abstract class
== "*": oper = MulOperation() elif operator == "/": oper = DivOperation() else: print("Wrong operator.") return operThe corresponding object can be instantiated by inputting the operation symbol through the simple factory above. Below is the code for the client.number_a = int(input("input a number:"))operator = str(input("input a operater(+ - * /):"))number_b = int(input("input a number:"))oper = OperationFactory.create_operate(operator)prin
2010-10-
In September 24, I started to look at the big talk design pattern and felt very good. At that time, I decided to read 23 design patterns during the 11 S and use C ++ to implement the code again, I spent three days in structure 11 and then worked overtime. I finally read it again. I only wrote a few chapters of code, and then I wrote it until now. I will write it well from today, one design pattern per day.
The factory mode starts with a simp
instances. However, once the factory is out of the question, all instances cannot be used.Copyright Notice:1) original works, from "Clevercode's blog" , please be sure to mention the following original address when reproduced , otherwise hold the copyright legal responsibility. 2) Original address : http://blog.csdn.net/clevercode/article/details/45692995 ( reprint must indicate this address ).3) welcome everyone to pay attention to my blog more wonderful content: Http://blog.csdn.net/CleverC
;_numbera = 10; the $oper->_numberb = 20; the Echo $oper->get_result ();Maintainable, reusable, scalable, flexibleAssociation: When a class ' knows ' another class, it can be associated (association)Aggregation: Represents a weak ' owning ' relationship, which reflects that a object can contain a B object, but the B object is not part of a object.Combination: is in a strong ownership relationship, embodies the strict part and the whole relationship, part and the whole life cycle.Big talk design
1. Quick calculator Mode
In emacs23, you can use the M-x quick-Calc command or the shortcut key C-x * Q to start the quick calculator mode. This is a very small tool. After it is started, it will prompt the input mathematical formula in minibuffer, and press enter to display the result. This
This article mainly introduces the calculator implemented by PHP based on the factory mode. The example analyzes the implementation principle and application skills of the php factory mode, which has some reference value, if you need a calculator, refer to the example in this article to describe the
As a friend in the jealousy group wrote a calculator, I made a special use of the simple factory model "coffee" I just learned. It felt so cool !! The emergence of the object-oriented design model is to save my messy code. Looking at my previous "Book of heaven", I feel impulsive !!!
The calculator mode is very simple and suitable for beginners to "practice ". Th
Implement a simple calculator program that requires: Use the Jsp+javabean mode implementation.The project source code is as follows:Files: calculator.jspThe JavaBean code used in this article is as follows:Package Cn.zq.domain;public class Calculator {private string Firstnum;private string Operator;private string secondnum; private string Result;public string Get
Simple factory mode-MFC calculator implementation (continuous operation)
The design pattern is the goal of refactoring. It plays an important role in code reuse and expansion. The importance of restructuring and design patterns is self-evident in learning object-oriented models. Then, the learning design model should be combined with software design and software coding, and driven by examples. This article
Programming of a policy mode codeusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;/// ///Summary description of Class1/// Public InterfaceCalculator//declaring a computed interface { DoubleCal (DoubleADoubleb); } Public classAdd:calculator//The interface implements the addition operation { Public DoubleCal (DoubleADoubleb) {Doubleresult =0; Result= A +b; returnresult; } } Public classSub:calcula
intvalue];Long long result;Switch (self.lastoperation) {Case Koperationtypeadd:result = Self.firstparam + Secondparam;BreakCase Koperationtypeminus:result = Self.firstparam-secondparam;BreakCase Koperationtypemultiply:result = Self.firstparam * SECONDPARAM;BreakCase Koperationtypedevide:result = Self.firstparam/secondparam;BreakDefaultBreak}Show final ResultsSelf.result_label.text = [NSString stringwithformat:@ "%LLD", result];The current result is the value of the first parameter of the next t
1, the ASP needs to change a lot of places Ah, id this place is spent more than 20 minutes-----2. The code is as followsUsing system;using system.collections.generic;using system.linq;using system.web;/// Using system;using system.collections.generic;using system.linq;using system.web;/// Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;using system.io;using System.text.regularexpressions;public partial class _
For a programmer who knows nothing about design patterns, maintenance costs are a deadly problem, so from now on, I'm going to start working hard, designing patterns, and documenting my learning outcomes.Production class
Abstract class Oper Abstraction classes
Class Add Plus
Class Sub minus
Class Mul Multiply
Class Div in addition to
Class Operate Calculation
abstract class Oper { public $num 1 = 0; public $num 2 = 0; abstract public function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.